﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Elsa.Workflows;
using Elsa.Workflows.Activities;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using T.FAS.Runtime.MF.Entity.ElsaEntity;

namespace T.FAS.Runtime.MF.Activities.ActivityInputOutput
{
    public class ActivityExecuteDetailHandlerFactory
    {
        public static AbsActivityExecuteDetailHandler GetHandler(
           IActivity activity,
           ActivityExecutionRecord activityExecutionRecord,
           IEnumerable<ResolvedVariable> runtimeVariables,
           WorkflowInstance workflowInstance)
        {
            var activityType = activity.GetType();
            AbsActivityExecuteDetailHandler handler = null;
            if (activityType == typeof(FasStartActivity))
            {
                handler = new FasStartNodeExecuteDetailHandler(activity, activityExecutionRecord, runtimeVariables, workflowInstance);
            }
            else if (activityType == typeof(JavaScriptActivity)
                || activityType == typeof(ActionExecuteActivity)
                || activityType == typeof(CDOActivity)
                || activityType == typeof(DataQueryActivity)
                || activityType == typeof(LLMActivity))
            {
                //这里随便挑了一个类型，现在主要获取Inputs和Outputs，如果还要获取其它属性，需要具体类型
                handler = new FasCodeActivityExecuteDetailHandler<JavaScriptActivity>(activity, activityExecutionRecord, runtimeVariables, workflowInstance);
            }
            else if (activityType == typeof(FasIterationActivity)
                || activityType == typeof(FasParallelIterationActivity)
                 || activityType == typeof(ForEach)
                || activityType == typeof(ParallelForEach))
            {
                handler = new FasIterationExecuteDetailHandler(activity, activityExecutionRecord, runtimeVariables, workflowInstance);
            }
            else if (activityType == typeof(ConditionBranchActivity)
                || activityType == typeof(IfActivity))
            {
                handler = new FasActivityExecuteDetailHandler(activity, activityExecutionRecord, runtimeVariables, workflowInstance);
            }
            else if (activityType == typeof(FasEndActivity))
            {
                handler = new FasEndActivityExecuteDetailHandler(activity, activityExecutionRecord, runtimeVariables, workflowInstance);
            }
            return handler;
        }
    }
}